const loadJs = async (jsList = []) => {
    const listSrc = (jsList || []).map((item) => {
        return `./../../js/${item}.js`
    });

    let promiseResolver, promiseRejecter;

    const promise = new Promise((resolve, reject) => {
        promiseResolver = resolve;
        promiseRejecter = reject;
    });


    const loadingArr = new Proxy({
        loading: true,
        value: []
    }, {
        set(target, p, newValue, receiver) {
           target[p] = newValue;
           if (p === 'loading' && !newValue) {
               promiseResolver();
           }
        }
    });

    const list = listSrc.map((item) => {
        const link = document.createElement('script');
        link.src = item;
        link.type = 'text/javascript';
        link.onload = function () {
            loadingArr.value.push(item);
            if (list.length === loadingArr.value.length) {
                loadingArr.loading = false;
            }
        }

        link.onerror = function () {
            console.log('error');
            promiseRejecter(`${item}加载失败`);
        }

        return link;
    });

    list.forEach((link) => {
        document.body.append(link);
    })

    return promise;
}
